package test;

import com.rory.util.EncodeUtil;
import com.rory.util.IpMacUtil;
import org.junit.Test;

import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;

/**
 * class: test1.
 * Created by Rory on 2016/11/22.
 * use:  .
 * other:  .
 */
public class test1 {
    @Test
    public void getIpAddress() {
        try {
            Enumeration<NetworkInterface> allNetInterfaces = NetworkInterface.getNetworkInterfaces();
            InetAddress ip = null;
            while (allNetInterfaces.hasMoreElements()) {
                NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement();
                if (netInterface.isLoopback() || netInterface.isVirtual() || !netInterface.isUp()) {
                    continue;
                } else {
                    Enumeration<InetAddress> addresses = netInterface.getInetAddresses();
                    while (addresses.hasMoreElements()) {
                        ip = addresses.nextElement();
                        if (ip != null && ip instanceof Inet4Address) {
                            System.out.print(ip.getHostAddress());
                        }
                    }
                }
            }
        } catch (Exception e) {
            System.out.print("IP地址获取失败"+e);
        }
    }

    @Test
    public void getMac(){
        System.out.print(IpMacUtil.getMacAddress());
    }

    @Test
    public void encode(){
        try {
            String a = EncodeUtil.shaEncode("123");
            System.out.print(a);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
